<%@ page language="java" import="com.tbrain.secretFriend.util.*,com.tbrain.secretFriend.service.*,com.tbrain.secretFriend.model.*,java.sql.*" pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%!
	private void update(String wish1Param,String detail,User user,WishService service){
		if(!wish1Param.trim().equals("")){
			Wish wish = new Wish();
			wish.setUserId(user.getUserId());
			wish.setDescription(wish1Param);
			wish.setComments(detail);
			service.insert(wish);
		}
	}
%>
<%   
	String wish1Param 	= request.getParameter("wish1");
	String wish2Param	= request.getParameter("wish2");
	String wish3Param	= request.getParameter("wish3");
	
	String wishDetail1Param = request.getParameter("wishDetail1");
	String wishDetail2Param	= request.getParameter("wishDetail2");
	String wishDetail3Param	= request.getParameter("wishDetail3");
	
	Connection conn = ConnectionHelper.getConnection();
	User user = (User)session.getAttribute("user");
	try{
		WishService wishService = new WishService(conn);
		wishService.deleteWishList(user);
		
		update(wish1Param,wishDetail1Param,user,wishService);
		update(wish2Param,wishDetail2Param,user,wishService);
		update(wish3Param,wishDetail3Param,user,wishService);
		request.getRequestDispatcher("./secretFriend.jsp").forward(request,response);
	}catch(Exception e){
		session.setAttribute("errorMessage",e);
		request.getRequestDispatcher("./index.jsp").forward(request,response);
	}finally{
		if(conn!=null){
			conn.close();
		}
	}
%>
</body>
</html>